<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Api\_InterfaceServer;
class ZgsController extends _InterfaceServer
{
	function __construct(Request $request) {
  		header("Access-Control-Allow-Origin: *");
  		header("Content-type:text/html;charset=utf-8");
  		//header("Access-Control-Allow-Credentials : true");
  		/*if(!isset($_SERVER['HTTP_X_YUN_KEY'])) $_SERVER['HTTP_X_YUN_KEY'] = '';
  		if(!isset($_SERVER['HTTP_X_YUN_ID'])) $_SERVER['HTTP_X_YUN_ID'] = '';
  		if(!isset($_SERVER['HTTP_X_YUN_KEY']) || !isset($_SERVER['HTTP_X_YUN_ID']) || empty($_SERVER['HTTP_X_YUN_KEY']) || empty($_SERVER['HTTP_X_YUN_ID'])) $GLOBALS['KEYID'] = true;
		if ($this->verifykey($_SERVER['HTTP_X_YUN_KEY'],$_SERVER['HTTP_X_YUN_ID']) == '非法请求') $GLOBALS['KEYID'] = true;*/
 	}
 	
    //首页
	public function index(Request $request){
		//if(isset($GLOBALS['KEYID'])) return $this->getDataJson(0,'非法请求','');
		$data['nav'] = DB::table('systemset_webnav')->first(['n1','n2','n3','n4','n4_1','n4_2','n4_3','n4_4']);
		return $this->getDataJson(1,'查询成功',$data);
	}

	//底部导航
	public function foot(Request $request){
		//if(isset($GLOBALS['KEYID'])) return $this->getDataJson(0,'非法请求','');
		$data['foot'] = DB::table('systemset_webfont')->first(['n1','n1_1','n1_2','n1_3','n1_4','n1_5','n2','n2_1','n2_2','n3','n3_1','n3_2','n3_3','n4','n4_1','n4_2']);
		return $this->getDataJson(1,'查询成功',$data);
	}

	//会议列表
	public function hy(){
		return DB::table('column_hy')->orderBy('id','desc')->limit(8)->get(['id','title']);
	}

	//医学动态列表
	public function yxdt(Request $request){
		//if(isset($GLOBALS['KEYID'])) return $this->getDataJson(0,'非法请求','');
		$datas = $request->only(['page']);
		$take_count = 7;
		$page = !empty($datas['page']) ? $datas['page'] : 1;
		$data['ycx'] = DB::table('column_ycx')->orderBy('id','desc')->skip(($page-1)*$take_count)->take($take_count)->get(['id','title_pic','title','brief']);
		foreach ($data['ycx'] as $key=>$value) $value->title_pic=self::SERVER_DOMAIN.$value->title_pic;
		$data['ycx_num'] = ceil(DB::table('column_ycx')->count()/$take_count);
		$data['hytz'] = DB::table('banner')->first(['banner_url','link_url']);
		$data['hytz']->banner_url = self::SERVER_DOMAIN.$data['hytz']->banner_url;
		$data['hy'] = $this->hy();
		return $this->getDataJson(1,'查询成功',$data);
	}

	//动态详情
	public function yxdt_qx(Request $request){
		//if(isset($GLOBALS['KEYID'])) return $this->getDataJson(0,'非法请求','');
		$datas = $request->only(['column_ycx_id']);
		$response = ['column_ycx_id'=>'动态id'];
		if (! empty ( $ex = $this->paramVerifyExist ( 'column_ycx_id') )) return $this->jsonStatus1000 ( "请传递参数[$response[$ex]]" );
		if (! empty ( $ex = $this->paramVerifyEmpty ( 'column_ycx_id' ) )) return $this->jsonStatus1000 ( "[$response[$ex]]不能为空" );
		$data['ycx'] = DB::table('column_ycx')->where(['id'=>$datas['column_ycx_id']])->first(['id','title','add_time','author','origin','details']);
		$data['ycx']->add_time = date('Y-m-d H:i:s',$data['ycx']->add_time);
		if(count($data['ycx']) == 0)
			return $this->getDataJson(0,'数据不存在或已被删除',$data);
		else
			return $this->getDataJson(1,'查询成功',$data);
	}

	//会议详情
	public function hy_qx(Request $request){
		//if(isset($GLOBALS['KEYID'])) return $this->getDataJson(0,'非法请求','');
		$datas = $request->only(['column_hy_id']);
		$response = ['column_hy_id'=>'会议id'];
		if (! empty ( $ex = $this->paramVerifyExist ( 'column_hy_id') )) return $this->jsonStatus1000 ( "请传递参数[$response[$ex]]" );
		if (! empty ( $ex = $this->paramVerifyEmpty ( 'column_hy_id' ) )) return $this->jsonStatus1000 ( "[$response[$ex]]不能为空" );
		$data['hy'] = DB::table('column_hy')->where(['id'=>$datas['column_hy_id']])->first(['id','title','add_time','author','origin','details']);
		$data['hy']->add_time = date('Y-m-d H:i:s',$data['hy']->add_time);
		if(count($data['hy']) == 0)
			return $this->getDataJson(0,'数据不存在或已被删除',$data);
		else
			return $this->getDataJson(1,'查询成功',$data);
	}

	//专家名录列表
	public function zjml(Request $request){
		//if(isset($GLOBALS['KEYID'])) return $this->getDataJson(0,'非法请求','');
		$datas = $request->only(['page']);
		$take_count = 4;
		$page = !empty($datas['page']) ? $datas['page'] : 1;
		$data['zj'] = DB::table('column_zj')->orderBy('id','desc')->skip(($page-1)*$take_count)->take($take_count)->get(['id','title_pic','author','origin','brief']);
		foreach ($data['zj'] as $key=>$value) $value->title_pic=self::SERVER_DOMAIN.$value->title_pic;
		$data['zj_num'] = ceil(DB::table('column_ycx')->count()/$take_count);
		return $this->getDataJson(1,'查询成功',$data);
	}

	//直播培训列表
	public function zb(Request $request){
		//if(isset($GLOBALS['KEYID'])) return $this->getDataJson(0,'非法请求','');
		$datas = $request->only(['page','type']);
		$response = ['type'=>'类型'];
		if (! empty ( $ex = $this->paramVerifyExist ( 'type') )) return $this->jsonStatus1000 ( "请传递参数[$response[$ex]]" );
		if (! empty ( $ex = $this->paramVerifyEmpty ( 'type' ) )) return $this->jsonStatus1000 ( "[$response[$ex]]不能为空" );
		$take_count = 6;
		$page = !empty($datas['page']) ? $datas['page'] : 1;
		if($datas['type'] == 1){
			$data['zb'] = DB::table('column_zb')->where('ks_time','>',time())->orderBy('id','desc')->skip(($page-1)*$take_count)->take($take_count)->get(['id','title_pic','title','author','link_url','ks_time','js_time']);
			$data['zb_num'] = ceil(DB::table('column_zb')->where('ks_time','>',time())->count()/$take_count);
		}else if($datas['type'] == 2){
			$data['zb'] = DB::table('column_zb')->where('ks_time','<',time())->where('js_time','>',time())->orderBy('id','desc')->skip(($page-1)*$take_count)->take($take_count)->get(['id','title_pic','title','author','link_url','ks_time','js_time']);
			$data['zb_num'] = ceil(DB::table('column_zb')->where('ks_time','<',time())->where('js_time','>',time())->count()/$take_count);
		}else if($datas['type'] == 3){
			$data['zb'] = DB::table('column_zb')->where('js_time','<',time())->orderBy('id','desc')->skip(($page-1)*$take_count)->take($take_count)->get(['id','title_pic','title','author','link_url','ks_time','js_time']);
			$data['zb_num'] = ceil(DB::table('column_zb')->where('js_time','<',time())->count()/$take_count);
		}
		foreach ($data['zb'] as $key=>$value){
			$value->title_pic=self::SERVER_DOMAIN.$value->title_pic;
			$value->ks_time=date('m-d H:i',$value->ks_time);
			$value->js_time=date('m-d H:i',$value->js_time);
			$value->ztbq = $datas['type'];
		}
		return $this->getDataJson(1,'查询成功',$data);
	}

	//关于我们 -- 遗传云
	public function ycy(Request $request){
		$data['gsjs'] = DB::table('gsjspage')->first(['title','details']);
		$data['ptys'] = DB::table('ptyspage')->first(['title','details']);
		$data['ptyh'] = DB::table('ptyhpage')->first(['title','details']);
		$data['nav'] = DB::table('systemset_webnav')->first(['n4','n4_1','n4_2','n4_3','n4_4']);
		$data['hy'] = $this->hy();
		return $this->getDataJson(1,'查询成功',$data);
	}

	//关于我们 -- 中华医学遗传杂志
	public function zhyxzzs(Request $request){
		$data['zzjs'] = DB::table('zzjspage')->first(['title','brief','zzjs_pic','zgdw','zbdw','gntykh','gjbzkh','ywlx','zzrq','zzlx','sqzz','xqzz']);
		$data['zzjs']->zzjs_pic = self::SERVER_DOMAIN.$data['zzjs']->zzjs_pic;
		$data['bwhmd'] = DB::table('column_bwhmd')->limit(6)->get(['title_pic','author','origin','brief']);
		foreach ($data['bwhmd'] as $key=>$value) $value->title_pic=self::SERVER_DOMAIN.$value->title_pic;
		$data['nav'] = DB::table('systemset_webnav')->first(['n4','n4_1','n4_2','n4_3','n4_4']);
		$data['hy'] = $this->hy();
		return $this->getDataJson(1,'查询成功',$data);
	}

	//关于我们 -- 海医会-遗传与生殖专业委员会
	public function yhh(Request $request){
		$data['hxla'] = DB::table('hxlapage')->first(['title','details']);
		$data['ycsz'] = DB::table('ycszpage')->first(['title','details']);
		$data['wymd'] = DB::table('column_wymd')->limit(3)->get(['title_pic','author','origin','brief']);
		foreach ($data['wymd'] as $key=>$value) $value->title_pic=self::SERVER_DOMAIN.$value->title_pic;
		$data['nav'] = DB::table('systemset_webnav')->first(['n4','n4_1','n4_2','n4_3','n4_4']);
		$data['hy'] = $this->hy();
		return $this->getDataJson(1,'查询成功',$data);
	}

	//关于我们 -- 北京中科遗传与生殖医学研究院
	public function bjzk(Request $request){
		$data['yjs'] = DB::table('yjspage')->first(['title','brief','details']);
		$data['nav'] = DB::table('systemset_webnav')->first(['n4','n4_1','n4_2','n4_3','n4_4']);
		$data['hy'] = $this->hy();
		return $this->getDataJson(1,'查询成功',$data);
	}

}